package com.example.design.personal.observer.jdk;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

public class Demo2 {

    private PropertyChangeEvent propertyChangeEvent;

    private PropertyChangeSupport listeners = new PropertyChangeSupport(this);

    public Demo2() {

    }

    public PropertyChangeEvent getPropertyChangeEvent() {
        return propertyChangeEvent;
    }

    public void setPropertyChangeEvent(PropertyChangeEvent propertyChangeEvent) {
        this.propertyChangeEvent = propertyChangeEvent;
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        listeners.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener){
        listeners.removePropertyChangeListener(listener);
    }

    protected void firePropertyChange(PropertyChangeEvent propertyChangeEvent){

        //listeners.firePropertyChange(prop,oldValue,newValue);
        listeners.firePropertyChange(propertyChangeEvent);
    }

    public static void main(String[] args) {
        Demo2 demo2 = new Demo2();
        PropertyChangeListener listener = new TestPropertyChangeListener();
        demo2.addPropertyChangeListener(listener);

    }

}
